const { Sequelize, DataTypes, Op } = require('sequelize')
const {
  database,
  username,
  port,
  host,
  password
} = require('./config')

const db = new Sequelize( database, username, password, {
  define: {
    freezeTableName: true
  },
  host,
  port,
  dialect: 'mysql',
  pool: {
    max: 5,
    min: 0,
    idle: 30000
  }
});

(async () => {
  try {
    await db.authenticate();
    console.log('连接成功！');
  } catch (err) {
    console.error('连接失败！', err);
  }
})();

module.exports = {
  db,
  DataTypes,
  Op
};